package com.assignwork.vo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Data
public class WorkArrangeOtherVO {
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "ID")
    private Long id;

    @DateTimeFormat(pattern = DateUtil.PATTERN_DATE)
    @ApiModelProperty(value = "计划日期")
    private LocalDate planDate;

    @ApiModelProperty(value = "时间段")
    private String timeSpace;

    @ApiModelProperty(value = "时间段")
    private String timeSpaceName;

    @ApiModelProperty(value = "作业类型")
    private String otherWorkType;

    @ApiModelProperty(value = "作业类型")
    private String otherWorkTypeName;

    @ApiModelProperty(value = "作业说明")
    private String workInfo;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "作业区域")
    private Long area;

    @ApiModelProperty(value = "作业区域")
    private String areaName;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "作业位置")
    private Long position;

    @ApiModelProperty(value = "作业位置")
    private String positionName;

    @ApiModelProperty(value = "工人信息")
    private String workerInfo;

    @ApiModelProperty(value = "机械类型")
    private String machineKind;

    @ApiModelProperty(value = "机械类型")
    private String machineKindName;

    @ApiModelProperty(value = "机械单位")
    private String machineCorp;

    @ApiModelProperty(value = "机械单位")
    private String machineCorpName;

    @ApiModelProperty(value = "机械数量")
    private Integer machineCount;

    @ApiModelProperty(value = "机械信息")
    private String machineInfo;

    @ApiModelProperty(value = "货名")
    private String cargoType;

    @ApiModelProperty(value = "货名")
    private String cargoTypeName;

    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(value = "作业吨")
    private BigDecimal workTon;

    List<AssignWorkVO> listAssignWork;
    List<WorkArrangeWorkersVO> listWorker;

    public Map<String, AssignWorkVO> getMapAssignWork() {
        if (Func.isNotEmpty(listAssignWork)) {
            return listAssignWork.stream().filter(i -> "FLOW_MACHINE_OTHER".equals(i.getWorkType())).collect(Collectors.toMap(i -> i.getArrangeId().toString(), a -> a,(k1, k2)->k1));
        }
        return null;
    }

    public Map<String, AssignWorkVO> getMapWorkerAssignWork() {
        if (Func.isNotEmpty(listAssignWork)) {
            return listAssignWork.stream().filter(i -> "LOADER_OTHER".equals(i.getWorkType())).collect(Collectors.toMap(i -> i.getArrangeId().toString(), a -> a,(k1, k2)->k1));
        }

        return null;
    }

    public Map<String, AssignWorkVO> getMapWorkerOtherAssignWork() {
        if (Func.isNotEmpty(listAssignWork)) {
            return listAssignWork.stream().filter(i -> "LOADER_OTHER".equals(i.getWorkType())).collect(Collectors.toMap(i -> i.getArrangeId().toString(), a -> a,(k1, k2)->k1));
        }

        return null;
    }

}
